#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
#include <time.h>

static int find(int *arr, int len, int v)
{
    int i = 0;
    int ret = 0;

    for(i = 0; i < len; i++) {
        ret = ret || (arr[i] == v);
    }

    return ret;
}

int main(int argc, char* argv[])
{
    int pid = atoi(argv[1]); // process id
    int num = atoi(argv[2]); // define the number of signal
    union sigval sv = {0};

    int special[] = {SIGSTOP, SIGKILL, 32, 33};
    int slen = sizeof(special) / sizeof(*special);
    int i = 0;

    srand((int)time(NULL));

    printf("current pid(%d) ...\n", getpid());

    for (i = 0; i < num; i++) {
        int sig = 0;

        do {
            sig = rand() % 33 + 32; // 随机产生可靠信号
        } while (find(special, slen, sig));

        printf("sig[%d] = %d\n", i, sig);
        sv.sival_int = i + 1;
        sigqueue(pid, sig, sv);
    }

    return 0;
}
